package com.fragment;

import java.util.List;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.adapter.WaybillAdapter;
import com.model.Waybill;
import com.ry.st.driver.R;

public class SearchFragment extends Fragment {
	ListView listView;
	WaybillAdapter adapter;
	Context ctx;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		ctx = getActivity();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		listView = (ListView) inflater.inflate(R.layout.search_frag, null);
        listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				Log.d("cyd", "onItemClick");
				adapter.getItem(arg2);
				getActivity().finish();
			}
		});
		return listView;
	}

	public void addData(List<Waybill> data) {
		// TODO Auto-generated method stub
		adapter = new WaybillAdapter(ctx, data);
		listView.setAdapter(adapter);
	}
}
